package com.liruo.learn.spring.mvc.enumconverter.api;

import com.liruo.learn.spring.mvc.model.enumeration.GenderEnum;

/**
 * @Author:liruo
 * @Date:2023-02-20-21:29:09
 * @Desc
 */
public class DefaultEnumConverterFactory<V> extends AbstractEnumConverterFactory<V>{
    @Override
    protected EnumConverter create(Class enumClazz) {
        EnumConverter<?, GenderEnum> converter = getConverter(GenderEnum.class);
        if(this.strategy == EnumValueStrategy.NAME){
            return new NameEnumConverter(enumClazz);
        }else if(this.strategy == EnumValueStrategy.ORDINAL){
            return new OrdinalEnumConverter(enumClazz);
        }
        throw new RuntimeException("can't create a EnumConverter, may be you strategy"
                + this.strategy.name() +  " is null");
    }
}
